<template>
	<el-dialog
		:title="`${title}标识`"
		:visible.sync="addFlagShow"
		width="50%"
		:before-close="cancel"
		append-to-body
		:close-on-click-modal="false"
		:close-on-press-escape="false"
	>
		<el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="所属层级" prop="parentId">
				<el-cascader
					v-model="form.parentId"
					style="width:100%;"
					:options="SignList"
					:props="{
						value: 'reminderTypeId',
						label: 'reminderName',
						children: 'nextRemindTypes',
						checkStrictly: true,
					}"
					clearable
					filterable
				></el-cascader>
			</el-form-item>
			<el-form-item label="标识KEY" prop="reminderKey">
				<el-input v-model="form.reminderKey"></el-input>
			</el-form-item>
			<el-form-item label="标识名称" prop="reminderName">
				<el-input v-model="form.reminderName"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button @click="cancel" size="small">取 消</el-button>
			<el-button type="primary" @click="addConfirm" size="small">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
	import { ReminderAddFlag } from '@/api/Reminder/index.js'
	import { jsonArray } from '@/api/productApi/file'
	export default {
		props: {
			addFlagShow: {
				type: Boolean,
				default: false
			},
			addFlagFunc: {
				type: Function,
				default: Function
			},
			SignList: {
				type: Array,
				default: Array
			},
			queryFundManagerList: {
				type: Function,
				default: Function
			},
			title: {
				type: String,
				default: ''
			}
		},

		data() {
			return {
				rules: {
					reminderKey: [{ required: true, message: '请填写标识KEY', trigger: 'blur' }],
					reminderName: [{ required: true, message: '请填写标识名称', trigger: 'blur' }]
				},
				form: {
					parentId: [],
					reminderKey: '',
					reminderName: ''
				}
			}
		},

		mounted() {},

		methods: {
			cancel() {
				this.form = {
					parentId: [],
					reminderKey: '',
					reminderName: ''
				}
				this.$refs['ruleForm'].resetFields()
				this.$emit('addFlagFunc')
			},

			edit(item) {
				const data = jsonArray(item)
				this.form = {
					...data
				}
			},

			// 新增或编辑
			addConfirm() {
				this.$refs.ruleForm.validate(valid => {
					if (valid) {
						const obj = {
							...this.form
						}
						if (Array.isArray(this.form.parentId)) {
							if (this.form.parentId.length) {
								obj.parentId = this.form.parentId[this.form.parentId.length - 1]
							} else {
								obj.parentId = '0'
							}
						} else {
							obj.parentId = this.form.parentId
						}
						ReminderAddFlag(obj).then(res => {
							if (res.msgCode === 'Y') {
								this.$message({ showClose: true, message: res.msg, customClass: 'el-messageClass', type: 'success' })
								this.$emit('queryFundManagerList')
								this.cancel()
							}
						})
					} else {
						return false
					}
				})
			}
		}
	}
</script>
<style lang="scss" scoped ></style>
